package com.kaifamiao.converter;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.logging.Logger;

public class BooleanConverter implements Converter<String, Boolean> {

    private Logger logger = Logger.getLogger( this.getClass().getName() );

    @Override
    public Boolean convert(String source) {
        logger.info( "将 " + source + " 转换为 Boolean" );
        return "Y".equalsIgnoreCase( source );
    }

    @Override
    public JavaType getInputType(TypeFactory typeFactory) {
        return typeFactory.constructType(String.class);
    }

    @Override
    public JavaType getOutputType(TypeFactory typeFactory) {
        return typeFactory.constructType(Boolean.class);
    }

}
